<?php

namespace Common\Logic;

/**
 * 经销商-掌柜
 * @modify trainyao 2016-05-11 创建
 */
class DealerAdminLogic extends \Common\Controller\BaseController {

    /**
     * 获取经销商下的客栈
     * @modify zhangzhen 2017-1-5   创建
     * @param  id $dealerId  经销商Id
     * @return array                信息数组
     */
    public function getHotel($dealerId) {
        $dealerAdminModel = D('DealerAdmin');
        $dealerAdmin = $dealerAdminModel->getInfo($dealerId);
        foreach ($dealerAdmin as $key => $value) {
            $adminIds[] = $value['adminlogin_id'];
        }
        $adminIds = implode(',', $adminIds);

        $adminHotelModel = D('AdminHotel');  

        $where = array(
            'role' => 1,
            'isdelete' => NOT_DELETE,
        );  
        if (strpos($adminIds, ',') === false) {
            $where['adminlogin_id'] = $adminIds;
        } else {
            $where['adminlogin_id'] = array('in', $adminIds);
        }

        $count = $adminHotelModel->where($where)->count();
        $pageSize = C('PAGE_SIZE');
        $pageInfo['total'] = $count;
        $pageInfo['pageTotal'] = ceil($count/$pageSize);
        $page = new \Think\Page($count,$pageSize);
        $page->setConfig('size', 'small');
        $show = $page->show();// 分页显示输出
        $adminHotels = $adminHotelModel->where($where)->limit($page->firstRow.','.$page->listRows)->select();

        $hotelEntityModel = D('HotelEntity');
        $adminLoginModel = D('AdminLogin');
        $cityModel =  D('City');
        $districtModel = D('District');
        $data = array();
        foreach ($adminHotels as $key => $adminHotel) {
            $data[$key] = $hotelEntityModel->getInfo($adminHotel['hotelentity_id']);
            $temp = $adminLoginModel->getInfo($adminHotel['adminlogin_id']);
            $data[$key]['username'] = $temp['name'];
            $data[$key]['mobile'] = $temp['mobile'];
            $data[$key]['createdate'] = $temp['createtime'];
            // 选择语言
            switch (LANG_SET) {
                case 'zh_cn':
                    $data[$key]['cityname'] = explode('/', $cityModel->getName($data[$key]['city_id']))[0];
                    $data[$key]['areaname'] = explode('/', $districtModel->getName($data[$key]['district_id']))[0];
                    break;
                case 'en_us':
                    $data[$key]['cityname'] = explode('/', $cityModel->getName($data[$key]['city_id']))[1];
                    $data[$key]['areaname'] = explode('/', $districtModel->getName($data[$key]['district_id']))[1];
                    break;
                case 'zh_tw':
                    $data[$key]['cityname'] = explode('/', $cityModel->getName($data[$key]['city_id']))[2];
                    $data[$key]['areaname'] = explode('/', $districtModel->getName($data[$key]['district_id']))[2];
                    break;
                default:
                    $data[$key]['cityname'] = explode('/', $cityModel->getName($data[$key]['city_id']))[0];
                    $data[$key]['areaname'] = explode('/', $districtModel->getName($data[$key]['district_id']))[0];
                    break;
            }
        }
        $this->assign('dealerAdmin',$data);
        $this->assign('page',$show);// 赋值分页输出
        //$this->assign('pageInfo',$pageInfo);// 赋值分页输出
    }
}
